/** FASSIT (Forms of Selective Attention in Intelligent Transportation Systems)
 * Computational Creativity and Digital Media
 * Cognitive and Media Systems Group
 * Centre for Informatics and Systems of the University of Coimbra (CISUC)
 *
 * Copyright (c) 2010-2013 University of Coimbra, Portugal
 * All rights reserved.
 */

package poi.UncertaintyCalculator;

import java.util.HashMap;

import masterAgent.DBmanager.DBConnection;
import poi.Info.POI;
import poi.Info.Price;
import poi.Surprise.SurprisePrice;
import poi.Uncertainty.*;
import agent.Context.Goal;

/**
 * This class is used to calculate the Master agent Uncertainty for the
 * parameter Price
 * 
 * @author Hernani Costa
 * @version 0.1 date: 27/01/2013
 */
public class UncertaintyCalculatorForPrice {

	HashMap<Integer, UncertaintyPrice> poiUncertaintyPrice;

	/**
	 * ------------------------------------------------------------------------
	 * Constructor class
	 * ------------------------------------------------------------------------
	 * 
	 * @param pois
	 *            - list with the POIs that we intend to calculate the
	 *            uncertainty
	 */
	public UncertaintyCalculatorForPrice(HashMap<Integer, POI> pois) {
		poiUncertaintyPrice = new HashMap<Integer, UncertaintyPrice>();
		calculates_Uncertainty_Knowledge_About_Price(pois);
	}

	/**
	 * Calculates the Uncertainty for the parameter Price
	 * 
	 * @param pois
	 *            - list with the POIs that we intend to calculate the
	 *            Uncertainty
	 */
	private void calculates_Uncertainty_Knowledge_About_Price(
			HashMap<Integer, POI> pois) {
		UncertaintyPrice uncertaintyPrice = null;
		for (POI poi : pois.values()) {
			Price price = poi.getPrice();

			if (!price.hasPrice()){
				uncertaintyPrice = new UncertaintyPrice(0.33, 0.33, 0.33);
			} else if (price.getAveragePrice().equals("Cheap")) {
				uncertaintyPrice = new UncertaintyPrice(1.0, 0.0, 0.0);
			} else if (price.getAveragePrice().equals("Average")) {
				uncertaintyPrice = new UncertaintyPrice(0.0, 1.0, 0.0);
			} else if (price.getAveragePrice().equals("Expensive")) {
				uncertaintyPrice = new UncertaintyPrice(0.0, 0.0, 1.0);
			}
			poiUncertaintyPrice.put(poi.getPoiID(), uncertaintyPrice);
		}
	}

	// ------------------------------------------------------------------------
	// ------------------------GETs and SETs-----------------------------------
	// ------------------------------------------------------------------------

	public HashMap<Integer, UncertaintyPrice> getPoiUncertaintyPrice() {
		return poiUncertaintyPrice;
	}

	/**
	 * 
	 * @return a String with the Uncertainty values for the parameter Schedule,
	 *         for all POIs
	 */
	public String to_String() {
		String info = "";
		for (int poiID : poiUncertaintyPrice.keySet()) {
			info += "poiID: " + poiID + "\n\t"
					+ poiUncertaintyPrice.get(poiID).to_String() + "\n";
		}
		return info;
	}

	/**
	 * ------------------------------------------------------------------------
	 * Only for debug purpose
	 * ------------------------------------------------------------------------
	 */
	public static void main(String args[]) {
		// DBManager manager = new DBManager();
		DBConnection connector = new DBConnection();

		POI poi = connector.getPOI(1507669);
		// System.err.println("O pesquisado\n" + poi.to_String() + "\n\n");

		HashMap<Integer, POI> pois = connector.getPOIsNear(
				poi.getLocation(), 200, new Goal().getDinner());
		// for (POI p : pois) {
		// System.err.println(p.to_String());
		// }

		UncertaintyCalculatorForPrice m = new UncertaintyCalculatorForPrice(
				pois);
		System.out.println(m.to_String());
	}
}
